
from ctypes import *
import os.path
import sys
import platform

if platform.system() == 'Windows':
	c_extention = '.dll'
elif platform.system() == 'Linux':
	c_extention = '.so'
else:
	raise RuntimeError, platform.system() + ' is not supported'

def find_clib(name):
	path = os.path.join('.', name+c_extention)
	if os.path.exists(path):
		return path
	for dir in sys.path:
		path = os.path.join(dir, name+c_extention)
		if os.path.exists(path):
			return path
	raise RuntimeError, "Can't find dynamic shared library for " + name

def load_library(name):
	return cdll.LoadLibrary(find_clib(name))


